package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.AddressManagement;
import com.example.user.service.AddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class AddressController {

    @Autowired
    private AddressService addressService;


    /**
     * 地址的列表查询
     */
    @GetMapping("/getAdderssPage")
    public Result getAdderssPage(@RequestParam(defaultValue = "1") Integer pageNumber,@RequestParam(defaultValue = "10") Integer pageSize)
    {
        PageHelper.startPage(pageNumber, pageSize);
       List<AddressManagement> addressManagements= addressService.getAdderssPage();
       return Result.success(new PageInfo(addressManagements));
    }

    /**
     * 修改地址信息
     */

    @PutMapping("/updateAddress")
    public Result updateAddress(@RequestBody AddressManagement addressManagement) {
       Result result= addressService.updateAddress(addressManagement);
       return result;
    }

    /**
     * 新增接口
     */

    @PostMapping("/addAdderss")
    public Result addAdderss(@RequestBody AddressManagement addressManagement) {
        Result result= addressService.addAdderss(addressManagement);
        return result;
    }

    /**
     * 删除接口
     */

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        Result result= addressService.deleteById(id);
        return result;
    }


}
